class TaskListUI extends UIBase{

	private btn_close:BaseButton;
    private itemGp:eui.Group;
    private main_group:eui.Group;
    private headIconList = [];
    // private TaskItemList = [];
    private award:number;

    public constructor(data?) {
		super('TaskViewSkin', data);
	}

    public init(){
        this.width = GlobalManager.instance().curWidth();
        this.height = GlobalManager.instance().curHeight();

        this.postTaskInfo();
        this.fixIphoneX();
	}

    //屏幕适配x
    protected fixIphoneX()
    {
		if(GlobalManager.instance().isIphonex())
		this.main_group.top = Math.floor(GlobalManager.instance().curHeight()/34);
    }

    public addEvent(){
		super.addEvent();
		this.btn_close.addTapHandler(this.btnClose, this);
	}

    public removeEvent(){
		super.removeEvent();
		this.btn_close.removeTapHandler();
	}

    public postTaskInfo()
    {
        let openid = RoleCache.instance().openid
        UIManager.instance().showNormalLoading();
        HttpManager.instance().sendPost(GameConst.httpUrl + 'options/get_task_info', 'openid=' + openid ,(e)=>{
            UIManager.instance().hideNormalLoading();
            let data = JSON.parse(e);
            if(data.msg == 'ok'){
                this.headIconList = data.avatar;
                this.award = data.money;
                var arr = data.data;
                this.InitUI(arr);
            }
            
        })
    }

    public InitUI(data)
    {
        for(let k in data)
        {
            let index = parseInt(k);
            let da = {
                index : index,
                state: data[k]+"",
                icon:this.headIconList[k],
                money:this.award
            }
            let TaskItem = new taskItem(da);
            if(index <= 2)
            {
                //第一排
                TaskItem.x = 0 + index * (6 + TaskItem.width);
                TaskItem.y = 0;
            }
            else
            {
                //第二排
                TaskItem.x = 0 + (index - 3) * (6 + TaskItem.width);
                TaskItem.y = 6 + TaskItem.height;
            }
            TaskItem.name = "taskItem_" + index;
            this.itemGp.addChild(TaskItem);
        }
    }

    private btnClose(){
		this.remove(1);
	}

    public clear(){
		super.clear();
	}

}